<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="公司名称" prop="gsbh">
        <el-select v-model="queryParams.gsbh" filterable  placeholder="请选择公司名称" @change="handleQuery">
          <el-option
            v-for="gs in gsList"
            :key="gs.gsbh"
            :label="gs.gsmc"
            :value="gs.gsbh"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="项目名称" prop="xmbh">
        <el-select v-model="queryParams.xmbh" filterable  placeholder="请输入项目名称" @change="handleQuery">
          <el-option
            v-for="gs in xmList"
            :key="gs.xmbh"
            :label="gs.xmmc"
            :value="gs.xmbh"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="名称规格" prop="mcjgg">
        <el-input
          v-model="queryParams.mcjgg"
          placeholder="请输入名称规格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收据编号" prop="sjbh">
        <el-input
          v-model="queryParams.sjbh"
          placeholder="请输入收据编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日期">
        <el-date-picker
          v-model="daterangeRq"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="制单人" prop="zdr">
        <el-input
          v-model="queryParams.zdr"
          placeholder="请输入制单人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['zdgl:ddxxb:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="tjwblxddsjXz"
        >文本新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['zdgl:ddxxb:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['zdgl:ddxxb:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['zdgl:ddxxb:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <!-- 统计 -->
    <el-row :gutter="10" >
      <el-form   size="small" :inline="true" label-width="68px">
        <el-form-item label="数量合计" prop="totalSl">
          <el-input
            v-model="totalSl"
            readonly="readonly"
          />
        </el-form-item>
        <el-form-item label="金额合计" prop="totalAmount">
          <el-input
            v-model="totalAmount"
            readonly="readonly"
          />
        </el-form-item>
      </el-form>
    </el-row>

<!-- 列表 -->
    <el-table v-loading="loading" :data="ddxxbList"  @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" width="50" :show-overflow-tooltip="true" align="center" prop="ddbh" />
      <el-table-column label="收据编号" width="120" :show-overflow-tooltip="true" align="center" prop="sjbh" />
      <el-table-column label="公司名称" width="150" :show-overflow-tooltip="true" align="center" prop="gsbh" :formatter="formatGsmc"/>
      <el-table-column label="项目名称" width="150" :show-overflow-tooltip="true" align="center" prop="xmbh" :formatter="formatXmmc"/>
      <el-table-column label="日期" align="center" prop="rq" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.rq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="名称规格" width="150" align="center" :show-overflow-tooltip="true" prop="mcjgg" >
        <template slot-scope="scope">
          <span v-if="!scope.row.mcjggediting" class="link-type" @click="startEditing(scope.$index, scope.row,'mcjgg')">{{scope.row.mcjgg}}</span>
          <span v-else><el-input v-model="scope.row.mcjgg"  @keyup.enter.native="stopEditing(scope.$index, scope.row,'mcjgg')"/></span>
        </template>
      </el-table-column>
      <el-table-column label="单位" width="100" align="center" prop="dw" >
        <template slot-scope="scope">
          <span v-if="!scope.row.dwediting" class="link-type" @click="startEditing(scope.$index, scope.row,'dw')">{{scope.row.dw}}</span>
          <span v-else><el-input v-model="scope.row.dw"  @keyup.enter.native="stopEditing(scope.$index, scope.row,'dw')"/></span>
        </template>
      </el-table-column>
<!--      <el-table-column label="数量" align="center" prop="sl" >-->
<!--        <template slot-scope="scope">-->
<!--          <el-input-->
<!--            v-model="scope.row.sl"-->
<!--            size="small"-->
<!--            @blur="handleInputBlur(scope.row)"-->
<!--          ></el-input>-->
<!--          <span >{{ scope.row.sl }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="数量" align="center" prop="sl" width="150">
        <template slot-scope="scope">
          <span v-if="!scope.row.isEditing" class="link-type" @click="startEditing(scope.$index, scope.row,'sl')">{{scope.row.sl}}</span>
<!--          双击-->
<!--          <span v-if="!scope.row.isEditing" class="link-type" @dblclick="startEditing(scope.$index, scope.row)">{{scope.row.sl}}</span>-->
<!--          <span v-else><el-input v-model="scope.row.dj" @blur="djstopEditing(scope.$index, scope.row)"  @keyup.enter.native="djstopEditing(scope.$index, scope.row)"/></span>-->

          <span v-else><el-input v-model="scope.row.sl"  @keyup.enter.native="stopEditing(scope.$index, scope.row,'sl')"/></span>
        </template>
      </el-table-column>
      <el-table-column label="单价" align="center" prop="dj" width="150">
        <template slot-scope="scope">
          <span v-if="!scope.row.djediting" class="link-type" @click="startEditing(scope.$index, scope.row,'dj')">{{scope.row.dj}}</span>
          <span v-else><el-input v-model="scope.row.dj"  @keyup.enter.native="stopEditing(scope.$index, scope.row,'dj')"/></span>
        </template>
      </el-table-column>
      <el-table-column label="金额总价" align="center" prop="zj" width="150">
<!--        <template slot-scope="scope">-->
<!--          <el-tooltip class="item" effect="dark" placement="top">-->
<!--            <div slot="content">{{ scope.row.zj }}</div>-->
<!--            <el-button>{{ scope.row.zj }}</el-button>-->
<!--          </el-tooltip>-->
<!--        </template>-->
      </el-table-column>
      <el-table-column label="制单人" align="center" prop="zdr" />
      <el-table-column label="备注" align="center"  prop="remark"  :show-overflow-tooltip="true">
<!--        <template slot-scope="scope">-->
<!--          <el-popover trigger="hover" placement="top">-->
<!--            <p>{{ scope.row.remark }}</p>-->
<!--            <div slot="reference" class="name-wrapper">-->
<!--              <el-tag size="medium">{{ scope.row.remark }}</el-tag>-->
<!--            </div>-->
<!--          </el-popover>-->

<!--        </template>-->

      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['zdgl:ddxxb:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['zdgl:ddxxb:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="850px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="公司名称" prop="gsbh">
              <el-select v-model="form.gsbh" filterable  placeholder="请选择公司名称" @change="handleChangeGs">
                <el-option
                  v-for="gs in gsList"
                  :key="gs.gsbh"
                  :label="gs.gsmc"
                  :value="gs.gsbh"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目名称" prop="xmbh">
              <el-select v-model="form.xmbh" filterable  placeholder="请输入项目名称">
                <el-option
                  v-for="gs in xmByGsbhList"
                  :key="gs.xmbh"
                  :label="gs.xmmc"
                  :value="gs.xmbh"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="收据编号" prop="sjbh">
              <el-input v-model="form.sjbh" placeholder="请输入收据编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="制单人" prop="zdr">
              <el-input v-model="form.zdr" placeholder="请输入制单人" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="日期" prop="rq">
              <el-date-picker clearable
                v-model="form.rq"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="名称规格" prop="mcjgg">
              <el-input v-model="form.mcjgg" placeholder="请输入名称规格" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>

          <el-col :span="6">
            <el-form-item label="单位" prop="dw">
              <el-input v-model="form.dw" placeholder="请输入单位" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="数量" prop="sl">
              <el-input v-model="form.sl" placeholder="请输入数量" @blur="calDdzj"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="单价" prop="dj">
              <el-input v-model="form.dj" placeholder="请输入单价" @blur="calDdzj"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="金额总价" prop="zj">
              <el-input v-model="form.zj" placeholder="请输入金额总价" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加文本类型的信息  tjwblxddsj 添加文本类型订单数据-->
    <el-dialog title="添加文本类型订单数据" :visible.sync="tjwblxddsj" width="850px" append-to-body>
      <el-form ref="form1" :model="form" :rules="rulesText" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="公司名称" prop="gsbh">
              <el-select v-model="form.gsbh" filterable  placeholder="请选择公司名称" @change="handleChangeGs11">
                <el-option
                  v-for="gs in gsList"
                  :key="gs.gsbh"
                  :label="gs.gsmc"
                  :value="gs.gsbh"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目名称" prop="xmbh">
              <el-select v-model="form.xmbh" filterable  placeholder="请输入项目名称">
                <el-option
                  v-for="gs in xmByGsbhList"
                  :key="gs.xmbh"
                  :label="gs.xmmc"
                  :value="gs.xmbh"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="收据编号" prop="sjbh">
              <el-input v-model="form.sjbh" placeholder="请输入收据编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="制单人" prop="zdr">
              <el-input v-model="form.zdr" placeholder="请输入制单人" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="日期" prop="rq">
          <el-date-picker clearable
            v-model="form.rq"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="数据内容" prop="remark">
          <el-input v-model="form.sjnr" type="textarea" rows="20" placeholder="请输入数据内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormText">确 定</el-button>
        <el-button @click="cancelText">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listDdxxb, getDdxxb, delDdxxb, addDdxxb, updateDdxxb,calDdzj,addDdxxbByText,checkDdxxbByText,updateDdxxbByColumn } from "@/api/zdgl/ddxxb";
import { getGetGsxxIdList,getGetXmxxIdList,getXmmcByGsbh } from "@/api/zdgl/xmxxb";
import {runJob} from "@/api/monitor/job";
export default {
  name: "Ddxxb",
  data() {
    return {
      totalSl:0,//数量汇总
      totalAmount:0,//金额汇总
      totalCount:0,//总数量
      //公司列表
      gsList: [],
      xmList: [],
      xmByGsbhList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单信息表格数据
      ddxxbList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      tjwblxddsj: false,
      // 备注时间范围
      daterangeRq: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        gsbh: null,
        xmbh: null,
        mcjgg: null,
        sjbh: null,
        rq: null,
        zdr: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        gsbh: [
          { required: true, message: "公司名称不能为空", trigger: "change" }
        ],
        xmbh: [
          { required: true, message: "项目名称不能为空", trigger: "change" }
        ],
        mcjgg: [
          { required: true, message: "名称规格不能为空", trigger: "blur" }
        ],
        sjbh: [
          { required: true, message: "收据编号不能为空", trigger: "blur" }
        ],
        rq: [
          { required: true, message: "日期不能为空", trigger: "blur" }
        ],
        sl: [
          { required: true, message: "数量不能为空", trigger: "blur" }
        ],
        dw: [
          { required: true, message: "单位不能为空", trigger: "blur" }
        ],
        dj: [
          { required: true, message: "单价不能为空", trigger: "blur" }
        ],
        zj: [
          { required: true, message: "金额总价不能为空", trigger: "blur" }
        ],
        zdr: [
          { required: true, message: "制单人不能为空", trigger: "blur" }
        ],
      },
      rulesText: {
        gsbh: [
          {required: true, message: "公司名称不能为空", trigger: "change"}
        ],
        xmbh: [
          {required: true, message: "项目名称不能为空", trigger: "change"}
        ],
        sjbh: [
          {required: true, message: "收据编号不能为空", trigger: "blur"}
        ],
        rq: [
          {required: true, message: "日期不能为空", trigger: "blur"}
        ],
        zdr: [
          {required: true, message: "制单人不能为空", trigger: "blur"}
        ],
        sjnr: [
          {required: true, message: "数据内容不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getGetGsxxIdList();//公司信息表
    this.getGetXmxxIdList();//项目信息表
  },
  methods: {
    //数量的编辑模式
    startEditing(index, row,lb){
      // 启用编辑模式：设置当前行的isEditing属性值为true，使用 this.$set 同步更新视图为文本框
      if('sl'==lb){
        this.$set(row, 'isEditing', true);
      }else if('dw'==lb){
        //单位
        this.$set(row, 'dwediting', true);
      }else if('mcjgg'==lb){
        //规格名称
        this.$set(row, 'mcjggediting', true);
      } else{
        //单价
        this.$set(row, 'djediting', true);
      }
    },
    stopEditing(index, row, lb){
      if ("sl" == lb || "dj" == lb) {//计算数量和单价
        // 禁用编辑模式：设置当前行的isEditing属性值为false，使用 this.$set 同步更新视图为文本
        if ('sl' == lb) {
          this.$set(row, 'isEditing', false);
        } else {
          this.$set(row, 'djediting', false);
        }
        // 这里可以添加保存或其他逻辑
        // 调用接口，更新数据
        var sl = row.sl;
        var dj = row.dj;
        if (this.isCheckEmpty(sl)) {
          if ('sl' == lb) {
            this.$set(row, 'isEditing', true);
          } else {
            this.$set(row, 'djediting', true);
          }
          this.$modal.msgError("数量不能为空");
          return false;
        }
        if (this.isCheckEmpty(dj)) {
          if ('sl' == lb) {
            this.$set(row, 'isEditing', true);
          } else {
            this.$set(row, 'djediting', true);
          }
          this.$modal.msgError("单价不能为空");
          return false;
        }
        if (Number(dj) <= 0) {
          if ('sl' == lb) {
            this.$set(row, 'isEditing', true);
          } else {
            this.$set(row, 'djediting', true);
          }
          this.$modal.msgError("单价应该大于0");
          return false;
        }
        if (Number(sl) <= 0) {
          if ('sl' == lb) {
            this.$set(row, 'isEditing', true);
          } else {
            this.$set(row, 'djediting', true);
          }
          this.$modal.msgError("数量应该大于0");
          return false;
        }
        updateDdxxbByColumn(row).then(rr => {
          row.zj = rr.data.zj;
          return row;
        }).catch(function (error) {
        });
      }
      if ("dw" == lb || "mcjgg" == lb) {//更新 单位  规格名称
        // 禁用编辑模式：设置当前行的isEditing属性值为false，使用 this.$set 同步更新视图为文本
        if ('dw' == lb) {
          this.$set(row, 'dwediting', false);
        } else if ('mcjgg' == lb) {
          this.$set(row, 'mcjggediting', false);
        }
        if ('dw' == lb) {//单位
          var dw = row.dw;
          if (this.isCheckEmpty(dw)) {
            this.$set(row, 'dwediting', true);
            this.$modal.msgError("单位不能为空");
            return false;
          }
        }
        if ('mcjgg' == lb) {//单价
          var mcjgg = row.mcjgg;
          if (this.isCheckEmpty(mcjgg)) {
            this.$set(row, 'mcjggediting', true);
            this.$modal.msgError("规格名称不能为空");
          }
          var up={};
          up.ddbh=row.ddbh;
          up.dw=row.dw;
          up.mcjgg=row.mcjgg;
          updateDdxxb(up).then(response => {
          });
        }

      }


    },
    submitFormText(){
      this.$refs["form1"].validate(valid => {
        if (valid) {
          var forms = this.form;
          checkDdxxbByText(forms).then(rr => {
            var checkMsg = rr.data;
            if (checkMsg != null && "" != checkMsg) {//如果是1的话，代表有问题
              this.$modal.confirm(checkMsg + '，是否继续新增？').then(() => {
                return addDdxxbByText(forms);
              }).then((response) => {
                this.$modal.msgSuccess("批量新增成功");
                this.tjwblxddsj = false;//新增成功，关闭弹窗
                this.getList();
              }).catch(() => {
              });
            } else {
              addDdxxbByText(forms).then(response => {
                this.$modal.msgSuccess("批量新增成功");
                this.tjwblxddsj = false;//新增成功，关闭弹窗
                this.getList();
              });
            }
          });
        }
      });
    },
    cancelText(){
      this.tjwblxddsj = false;
      this.reset();
    },
    //计算总金额
    calDdzj(){
      console.log(this.form.dj)
      console.log(this.form.sl)
      if(this.form.dj!=null &&this.form.dj!="" &&this.form.dj!=undefined &&
        this.form.sl!=null &&this.form.sl!="" &&this.form.sl!=undefined
        ){
        calDdzj(this.form).then(response => {
          console.log(response);
          this.form.zj =response.data;
        });
      }

    },
    //新增或者修改点击公司时候
    handleChangeGs(){
      var tempLdXMxx = [];//暂时存的联动
      for (var i = 0; i < this.xmList.length; i++) {
          var xm = this.xmList[i];
          if (xm.gsbh == this.form.gsbh) {
              tempLdXMxx.push(xm);
          }
      }
      if(tempLdXMxx != null){
        this.xmByGsbhList = tempLdXMxx;
      }
    },
    //文本
    handleChangeGs11(){
      this.form.xmbh=null;
      var tempLdXMxx = [];//暂时存的联动
      for (var i = 0; i < this.xmList.length; i++) {
          var xm = this.xmList[i];
          if (xm.gsbh == this.form.gsbh) {
              tempLdXMxx.push(xm);
          }
      }
      if(tempLdXMxx != null){
        this.xmByGsbhList = tempLdXMxx;
      }
    },
    //row：当前行的数据对象。
    // column：当前列的定义。
    // cellValue：当前单元格的值，由 prop 属性指定。
    // index：当前行的索引。
    //格式化项目名称
    formatXmmc(row, column, cellValue, index){
      var xmbh = row.xmbh;
      for (var i = 0; i < this.xmList.length; i++) {
          var xmxx = this.xmList[i];
          if (xmxx.xmbh == xmbh) {
              return xmxx.xmmc;
          }
      }

    },
    //row：当前行的数据对象。
    // column：当前列的定义。
    // cellValue：当前单元格的值，由 prop 属性指定。
    // index：当前行的索引。
    //格式化公司名称
    formatGsmc(row, column, cellValue, index){
      var gsbh = row.gsbh;
      for (var i = 0; i < this.gsList.length; i++) {
          var gsxx = this.gsList[i];
          if (gsxx.gsbh == gsbh) {
              return gsxx.gsmc;
          }
      }

    },
    //获取列表
    getGetGsxxIdList(){
      getGetGsxxIdList().then(response=>{
        this.gsList = response.data;
      });
    },
    //获取列表
    getGetXmxxIdList(){
      getGetXmxxIdList().then(response=>{
        this.xmList = response.data;
      });
    },
    /** 查询订单信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeRq && '' != this.daterangeRq) {
        this.queryParams.params["beginRq"] = this.daterangeRq[0];
        this.queryParams.params["endRq"] = this.daterangeRq[1];
      }
      listDdxxb(this.queryParams).then(response => {
        this.ddxxbList = response.rows;
        this.total = response.total;
        this.totalSl = response.statisticsMap.totalSl;
        this.totalAmount = response.statisticsMap.totalAmount;
        this.totalCount = response.statisticsMap.totalCount;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ddbh: null,
        gsbh: null,
        xmbh: null,
        mcjgg: null,
        sjbh: null,
        rq: null,
        sl: null,
        dw: null,
        dj: null,
        zj: null,
        zdr: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        sjnr: null
      };
      this.resetForm("form");
      this.resetForm("form1");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeRq = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.ddbh)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单信息";
    },
    /** 文本按钮操作 */
    tjwblxddsjXz() {
      this.reset();
      this.tjwblxddsj = true;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const ddbh = row.ddbh || this.ids
      getDdxxb(ddbh).then(response => {
        this.form = response.data;
        this.handleChangeGs();
        this.form.xmbh = response.data.xmbh;
        this.open = true;
        this.title = "修改订单信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.ddbh != null) {
            updateDdxxb(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDdxxb(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ddbhs = row.ddbh || this.ids;
      this.$modal.confirm('是否确认删除订单信息编号为"' + ddbhs + '"的数据项？').then(function() {
        return delDdxxb(ddbhs);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('zdgl/ddxxb/export', {
        ...this.queryParams
      }, `ddxxb_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
